package com.hutra.utils{
	import flash.events.Event;
	import flash.events.HTTPStatusEvent;
	import flash.events.IEventDispatcher;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.events.SecurityErrorEvent;
	import flash.external.ExternalInterface;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	import flash.net.URLVariables;
	public class Track {
		/**
		 * @version 1.0.0.0
		 * @author hungconcon
		 */
		public function Track() {
		}
		/**
		 * Create methods to save the traces, the traces can be commit to the server and write into file
		 * @param	str
		 * @param	...args
		 */
		public static function log(str:String,...args):void {
			try {
				
				trace(str);
				//try{ExternalInterface.call("onChatAll",str+"<br>");}catch (e:Error){}
				for (var i:int; i < args.length; i++){
					trace(args[i]);
					//try{ExternalInterface.call("onLogBrowse",args[i]+"<br>");}catch (e:Error){}
				}				
				
				// Call server write to file!
			}catch (e:Error){}
		}
		public static function write(data:String):void {
            //var loader:URLLoader = new URLLoader();
            //configureListeners(loader);
            //var request:URLRequest = new URLRequest("http://117.103.198.172/fish_qa/logerror.php");
				//request.method = URLRequestMethod.GET;
				//
			//var variables:URLVariables = new URLVariables();
				//variables.id    = 1;
				//variables.error = data;
				//variables.clear = 0;
				//
				//request.data = variables;
            //try {
                //loader.load(request);
            //} catch (error:Error) {
                //trace("Unable to load requested document.");
            //}
        }
        private static function configureListeners(value:IEventDispatcher):void {
            //value.addEventListener(Event.COMPLETE, completeHandler);
            //value.addEventListener(Event.OPEN, openHandler);
            //value.addEventListener(ProgressEvent.PROGRESS, progressHandler);
            //value.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
            //value.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
            //value.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
        }
        private static function completeHandler(event:Event):void {
            var loader:URLLoader = URLLoader(event.target);
            trace("completeHandler: " + loader.data);
        }
        private static function openHandler(event:Event):void {
            trace("openHandler: " + event);
        }
        private static function progressHandler(event:ProgressEvent):void {
            trace("progressHandler loaded:" + event.bytesLoaded + " total: " + event.bytesTotal);
        }
        private static function securityErrorHandler(event:SecurityErrorEvent):void {
            trace("securityErrorHandler: " + event);
        }
        private static function httpStatusHandler(event:HTTPStatusEvent):void {
            trace("httpStatusHandler: " + event);
        }
        private static function ioErrorHandler(event:IOErrorEvent):void {
            trace("ioErrorHandler: " + event);
        }

	}
}